package com.jameskarl.amap.map

import com.amap.api.maps.AMapUtils
import com.jameskarl.amap.map.bean.LatLngData
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

class MapUtils : MethodChannel.MethodCallHandler {

    override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
        when (call.method) {
            "distance" -> distance(call, result)
            else ->
                result.notImplemented()
        }
    }

    fun distance(call: MethodCall, result: MethodChannel.Result) {
        val args = call.arguments as Map<*, *>
        val from = LatLngData(args["from"] as Map<*, *>)
        val to = LatLngData(args["to"] as Map<*, *>)
        result.success(AMapUtils.calculateLineDistance(from.toLatLng(), to.toLatLng()))
    }

}